package com.patsnap.data.npd.dw.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.patsnap.data.npd.dw.mapper.ads.journal.AdsJournalMapper;
import com.patsnap.data.npd.dw.repository.AdsJournalRepository;
import com.patsnap.data.npd.dw.repository.DBException;
import com.patsnap.data.npd.dw.schema.ads.journal.AdsJournal;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class AdsJournalRepositoryImpl extends BaseRepositoryImpl implements AdsJournalRepository {

    public AdsJournalRepositoryImpl(SqlSessionFactory sessionFactory) {
        super(sessionFactory);
    }


    @Override
    public AdsJournal queryByIssn(String issn) throws DBException {
        try (SqlSession session = sessionFactory.openSession()) {
            AdsJournalMapper mapper = session.getMapper(AdsJournalMapper.class);
            LambdaQueryWrapper<AdsJournal> wrapper = new LambdaQueryWrapper<AdsJournal>().eq(AdsJournal::getIssn, issn);
            return mapper.selectOne(wrapper);
        } catch (Exception e) {
            throw new DBException(e);
        }
    }

    @Override
    public AdsJournal queryByEIssn(String eissn) throws DBException {
        try (SqlSession session = sessionFactory.openSession()) {
            AdsJournalMapper mapper = session.getMapper(AdsJournalMapper.class);
            LambdaQueryWrapper<AdsJournal> wrapper = new LambdaQueryWrapper<AdsJournal>().eq(AdsJournal::getEissn, eissn);
            return mapper.selectOne(wrapper);
        } catch (Exception e) {
            throw new DBException(e);
        }
    }
}
